<template>
  <div class="post-container">
    <div class="post-image">
      <img
        :src="itemData.imgUrl"
        alt="Post image"
      />
    </div>
    <div class="post-content">
      <div class="post-title">{{ itemData.title }}</div>
      <div class="post-details">
        {{ itemData.preview }}
      </div>
      <div class="post-footer">
        <span class="post-date">{{ itemData.createdDate }}</span>
        <span class="post-comments">0</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, watch, ref } from 'vue'

const props = defineProps({
  item: {
    type: Object,
    default: () => ({})
  }
})
const itemData = ref(props.item)
watch(
  () => props.item,
  (newVal) => {
    console.log(newVal)
    itemData.value = newVal
  }
)
</script>

<style scoped lang="scss">
.post-container {
  display: flex;
  align-items: flex-start;
  width: 100%;
  max-width: 1200px;
  //   border-radius: 10px;
  overflow: hidden;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 16px;
}

.post-image {
  width: 20%;
  max-width: 282px;
  img {
    width: 180px;
    height: 106px;
    // height: auto;
    border-radius: 10px;
    object-fit: cover;
  }
}

.post-content {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-left: 16px;
  width: 80%;

  .post-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
  }

  .post-details {
    font-size: 14px;
    color: #666;
    line-height: 1.5;
  }

  .post-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;

    .post-date {
      font-size: 12px;
      color: #999;
    }

    .post-comments {
      font-size: 12px;
      color: #999;
      &:before {
        content: '💬';
        margin-right: 4px;
      }
    }
  }
}
</style>
